//
//  TEAppHelper.h
//  ThaiExpress
//
//  Created by Le Quang Vinh on 7/11/13.
//  Copyright (c) 2013 Fruity. All rights reserved.
//

#import <Foundation/Foundation.h>

#define SuppressPerformSelectorLeakWarning(Stuff) \
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
Stuff; \
_Pragma("clang diagnostic pop") \
} while (0)

#pragma mark Logs

/*
 * defines a custom log tool in order to provide detailed log content with callee class name & file line number
 */
#ifdef DEBUG

#define DEBUGLog(...) extendedLog( [NSString stringWithFormat:@"%s (Line %d): ", __PRETTY_FUNCTION__, __LINE__], __VA_ARGS__ )
#define DLog(...) extendedLog( [NSString stringWithFormat:@"%s (Line %d): ", __PRETTY_FUNCTION__, __LINE__], __VA_ARGS__ )
#define DEBUGLogBegin(x) extendedLog( [NSString stringWithFormat:@"%s BEGIN - ", __PRETTY_FUNCTION__, @#x )
#define DEBUGLogEnd(x) extendedLog( [NSString stringWithFormat:@"%s END - ", __PRETTY_FUNCTION__, @#x )
#define NSLog DEBUGLog
#else

#define DEBUGLog(...)
#define DEBUGLogBegin(x)
#define DEBUGLogEnd(x)
#define NSLog DEBUGLog

#endif
#ifdef __cplusplus
extern "C" {
#endif
    /*
     * add extended information on a classical NSLog command
     */
    void extendedLog(NSString* extendedInfo, NSString* format, ...);
    
#pragma mark -
#pragma mark Memory Handling
    
    /*
     * define MACRO that ensure any pointer would get properly and safely released
     */
#define RELEASE_SAFELY(__POINTER){[__POINTER release]; __POINTER = nil;}
#define RELEASE_SAFELY_CF(X)  { if (X) {CFRelease(X); X = NULL;} }
    
#pragma mark - UIColor extends
    //Custom UIColor to use RGB define
#define UIColorRGB(r, g, b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0]
#define UIColorRGBA(r, g, b, a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
    
    static inline UIColor* UIColorFromRGBA(long rgbValue, float alpha) {
        return [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0
                               green:((float)((rgbValue & 0xFF00) >> 8))/255.0
                                blue:((float)(rgbValue & 0xFF))/255.0 alpha:alpha];
    }
    static inline UIColor* UIColorFromRGB(long rgbValue) {
        return UIColorFromRGBA(rgbValue, 1.0);
    }
    
#ifdef __cplusplus
}
#endif

#define UI_USER_INTERFACE_IS_PAD() (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define UI_USER_INTERFACE_IS_PHONE() (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)

#define UIViewAutoresizingFlexibleAll UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin

@interface TEAppHelper : NSObject

+ (NSString *)currentVersion;
+ (NSString *)applicationDocumentDirectory;

@end
